package com.chentianyu.demo01.controller;

import com.chentianyu.demo01.obj.Students;
import com.chentianyu.demo01.service.StudentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "*",maxAge = 3600)
public class StudentsController {

    @Autowired
    StudentsService studentsService;

    @GetMapping("/hello")
    public String sayHello(){
        return "hello welcome";
    }

    @GetMapping("/allStudents")
    public List<Students> selectAllStudents(){
        return studentsService.selectAllStudents();
    }

    @PostMapping("/postStudent")
    public void postStudent(@RequestParam("uid") Integer uid,@RequestParam("name") String name,@RequestParam("age") Integer age){
        studentsService.postStudent(uid, name, age);
    }

    @PostMapping("/setSex_uid")
    public void setSex_uid(@RequestParam("uid") Integer uid,@RequestParam("sex") String sex){
        studentsService.setSex_uid(uid, sex);
    }
}
